package com.api.weavernorth.promotionPlan;

import com.weavernorth.promotionPlan.pojo.*;
import com.weavernorth.promotionPlan.service.promPlanService;
import com.weavernorth.util.Logger4jUtil;
import net.sf.json.JSONArray;
import org.apache.log4j.Logger;
import net.sf.json.JSONObject;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 王文彬
 * @date 2020/11/4 14:52
 * @description 描述：根据V8传入的数据生成促销方案流程的接口
 * 接口地址：http://testoa.chinaerdos.com:8081/api/Sales/promotion
 */
@Path("/Sales")
public class promotionPlanApi extends HttpServlet {
    private Logger log = Logger4jUtil.getLoggerByName("/action/api/promotionPlanApi/");
    @POST
    @Path("/promotion")
    @Produces(MediaType.APPLICATION_JSON)
    public String promotionPlanApi(@Context HttpServletRequest httpservletrequest, @Context HttpServletResponse httpservletresponse, JSONObject jsonObject){
        String localDate=new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime());
        log.info("促销方案自动创建流程接口：");
        log.info("V8传过来的数据："+jsonObject.toString());
        log.info("当前日期："+localDate);
        promPlanService service=new promPlanService();
        JSONObject jsonReturn =null;
        try {
            jsonReturn=service.createWorkFlow(jsonObject);
        }catch (Exception ex){
            jsonReturn=new JSONObject();
            jsonReturn.put("status","F");
            jsonReturn.put("message","失败,异常信息："+jsonReturn.toString());

        }
        return jsonReturn.toString();
    }
}
